package com.xd.pre.modules.security.ldap.userdetails;

import com.xd.pre.security.LoginType;
import com.xd.pre.security.PreSecurityUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ldap.core.ContextSource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.ldap.userdetails.LdapUserDetailsManager;

/**
 * Ldap用户信息
 * @author tangkaifei
 */
@Slf4j
public class PreLdapUserDetailsManager extends LdapUserDetailsManager {
    public PreLdapUserDetailsManager(ContextSource contextSource) {
        super(contextSource);
    }

    @Override
    public UserDetails loadUserByUsername(String username) {
        UserDetails userDetails = super.loadUserByUsername(username);
        return new PreSecurityUser(0, userDetails.getUsername(), userDetails.getPassword(),
                userDetails.getAuthorities(), LoginType.normal);
    }
}
